﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Negocio;


namespace Precentacion1
{
    public partial class frmDetalleCobranza : Form
    {
        int IdVenta;
        public frmDetalleCobranza(int paramIntIdVenta)
        {
          
            InitializeComponent();
            
             this.dateTimePicker1.Enabled = false;
            this.ConfigurarDataGridView(this.dataGridViewDetallesCobranzas);
            IdVenta = paramIntIdVenta;
            mostrate();
           ;
           // this.dataGridViewDetalleCobranza.DataSource = admCobranzas.ListarDetallesDeCobranza(paramIntIdVenta);
        }
        public void mostrate()
        {
            this.dataGridViewDetallesCobranzas.DataSource = admCobranzas.ListarDetallesDeCobranza(IdVenta);
            this.dataGridViewDetallesCobranzas.Columns["IdCobranza"].Visible = false;
            this.dataGridViewDetallesCobranzas.Columns["IdVenta"].Visible = false;


        }
        private void dataGridViewDetalleCobranza_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
        private void ConfigurarDataGridView(DataGridView paramDataGridView)
        {
            paramDataGridView.ReadOnly = true;
            paramDataGridView.MultiSelect = false;
            paramDataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            paramDataGridView.RowHeadersVisible = false;
            paramDataGridView.AllowUserToResizeRows = false;
            paramDataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            paramDataGridView.AlternatingRowsDefaultCellStyle.BackColor = Color.AliceBlue;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            //this.dataGridViewDetallesCobranzas.DataSource = admCobranzas.ListarDetallesDeCobranza(idVenta);
        }

        private void button1_Click_1(object sender, EventArgs e)
        {

        }

        private void buttonCobrar_Click(object sender, EventArgs e)
        {
            if (this.dataGridViewDetallesCobranzas.SelectedRows[0].Cells["leyendaDePago"].Value.ToString() == "PAGADO")
            {
                MessageBox.Show("El numero de cuota seleccionado ya fue cobrado");
                return;
            }

            if (MessageBox.Show("Desea realizar la cobranza?", /*Application.ProductName*/ "Confirmacion", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {
                admCobranzas.CobrarCuota(Convert.ToInt32(this.dataGridViewDetallesCobranzas.SelectedRows[0].Cells["IdCobranza"].Value), Convert.ToInt32(this.dataGridViewDetallesCobranzas.SelectedRows[0].Cells["IdVenta"].Value), Convert.ToInt32(this.dataGridViewDetallesCobranzas.SelectedRows[0].Cells["NroCuota"].Value));
                MessageBox.Show("La cobranza se realizo correctamente");
                mostrate();
            }
        }

        private void Descobrar_Click(object sender, EventArgs e)
        {
            if (this.dataGridViewDetallesCobranzas.SelectedRows[0].Cells["leyendaDePago"].Value.ToString() == "PAGADO")
            {
                if (MessageBox.Show("Deseaa modificar la cobranza?", /*Application.ProductName*/ "Confirmacion", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    admCobranzas.Descobrar(Convert.ToInt32(this.dataGridViewDetallesCobranzas.SelectedRows[0].Cells["IdCobranza"].Value));
                    MessageBox.Show("Se modifico correctamente");
                    mostrate();
                }
            }
            else
            {
                MessageBox.Show("La cuota seleccionada falta pagar");
            }
        }

     
        
        private void checkBox1_CheckedChanged_1(object sender, EventArgs e)
        {
            if (this.checkBox1.Checked == false)
            {
                this.dateTimePicker1.Enabled = false;
            }
            else
            {
                this.dateTimePicker1.Enabled = true;
            }
        }

        private void button1_Click_2(object sender, EventArgs e)
        {

            if (this.checkBox1.Checked == true)
            {
                if (this.dataGridViewDetallesCobranzas.SelectedRows.Count > 0)
                {
                    if (MessageBox.Show("Desea cambiar la fecha de la Cobranza seleccionada", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                    {
                        admCobranzas.cambiarFechaCobranza(this.dateTimePicker1.Value, Convert.ToInt32(this.dataGridViewDetallesCobranzas.SelectedRows[0].Cells["IdCobranza"].Value));
                        IdVenta = Convert.ToInt32(this.dataGridViewDetallesCobranzas.SelectedRows[0].Cells["IdVenta"].Value);
                        mostrate();
                    }

                }
                else
                    MessageBox.Show("Debe seleccionar una Cobranza");
            }
            else
                MessageBox.Show("Debe seleccionar una fecha nueva");
        }
            
           
       }
  }

